﻿Imports System.Collections.Generic
Imports System.Security.Claims
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Data.OleDb

' New Code - login.aspx.vb - 12 Jan 2014 - Gene Da Rocha - Redirecting Admin users to one screen and ordinary users to another. 

Partial Public Class Login
    Inherits Page


    Protected Sub LogIn(sender As Object, e As EventArgs)

        ' New Code - login.aspx.vb - 08 Jan 2014 - Gene Da Rocha - Check existence of user on Database

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString004").ConnectionString)
        Dim strsql As String



        ' prepare a two-statement command
        strsql = "SELECT COUNT(username), sms_usertype_fkid  FROM sms_register WHERE username= '" & UserName.Text & "' and thepassword='" & Password.Text & "'" & " group by username, sms_usertype_fkid"
        Dim objcmd As OleDbCommand = New OleDbCommand(strsql, oleDbConn)
        oleDbConn.Open()
        Dim dr As OleDbDataReader = objcmd.ExecuteReader()
        '  objcmd.ExecuteNonQuery()

        '  MsgBox("Numrows is >" + Convert.ToString(numrows) + " STRsql string = " + strsql)

        dr.Read()
        Dim totalRows As Long = CInt(dr(0))
        Dim theusertype As Long = CInt(dr(1))

        ' actual values are in the second resultset
        dr.NextResult()
        Dim currRow As Integer
        Do While dr.Read
            ' update the label
            currRow += 1
        Loop
        dr.Close()

        '    MsgBox("Usertype is " + Convert.ToString(theusertype))

        ' New Code - login.aspx.vb - 12 Jan 2014 - Gene Da Rocha - Redirecting Admin users to one screen and ordinary users to another. 
        If totalRows > 0 Then

            MsgBox("Successful Login !!")
            If theusertype = 1 Then
                Response.Redirect("Userinput.aspx")
            Else
                Response.Redirect("Admininput.aspx")
            End If
        Else
            MsgBox("Password is incorrect - Retry again ... ")
        End If
        oleDbConn.Close()
        
    End Sub
End Class
